package com.zhongyu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongyu.mapper.CangkuMapper;
import com.zhongyu.mapper.OrgMapper;
import com.zhongyu.pojo.Cangku;
import com.zhongyu.pojo.GoodsType;
import com.zhongyu.pojo.Org;
import com.zhongyu.service.OrgService;
import com.zhongyu.vo.OrgVo;
import com.zhongyu.vo.PageResult;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service("orgService")
public class OrgServicelmpl extends ServiceImpl<OrgMapper, Org> implements OrgService {
    @Resource
    private OrgMapper orgMapper;

    @Override
    public PageResult searchAll(Integer pageNo, Integer pageSize, OrgVo orgVo) {
        LambdaQueryWrapper<Org> wrapper= Wrappers.<Org>lambdaQuery();
        wrapper.like(!StringUtils.isEmpty(orgVo.getOrgName()),Org::getOrgName,orgVo.getOrgName())
       .like(!StringUtils.isEmpty(orgVo.getOrgPhone()),Org::getOrgPhone,orgVo.getOrgPhone());
        Page page=new Page(pageNo,pageSize);
        List<Org> list=baseMapper.findAll(page,wrapper);
        return new PageResult(list,page.getTotal());
    }

    @Override
    public List<Org> searchAll() {
        return  orgMapper.selectList(null);
    }

    @Override
    public void add(Org org) {
orgMapper.insert(org);
    }

    @Override
    public void del(Integer id) {
 orgMapper.deleteById(id);
    }

    @Override
    public void update(Org org) {
        orgMapper.updateById(org);
    }
}
